﻿/*
 * Autore: Paolo Farina
 */

using System.ComponentModel;
using System.Windows;
using System.Windows.Input;

namespace RecipesManager.MainControls.CategorySubControls
{
    /// <summary>
    /// Logica di interazione per CategoryAddWindow.xaml
    /// </summary>
    public partial class CategoryAddWindow : Window
    {
        readonly CategoryMainPane _actualPanel;

        public CategoryAddWindow()
        {
            InitializeComponent();
            _actualPanel=new CategoryMainPane("") {FromAnotherWindow = true, save_button = {IsDefault = true}, close_button = {IsCancel = true}};
            categoryContentPane.Content = _actualPanel;
            CommandManager.RegisterClassCommandBinding(typeof(CategoryAddWindow), Savebinding);
            CommandManager.RegisterClassCommandBinding(typeof(CategoryAddWindow), Closebinding);
        }

        void Save_Context()
        {
            if (!_actualPanel.Save()) return;
            DialogResult = true;
            Close();
        }

        void Close_Context()
        {
            DialogResult = false;
            Close();    
        }

        #region SaveCommandRegion

        CommandBinding Savebinding = new CommandBinding(ApplicationCommands.Save, CommandSaveHandler);

        static void CommandSaveHandler(object target, ExecutedRoutedEventArgs e)
        {
            ((CategoryAddWindow)target).Save_Context();
           
        }

        #endregion

        #region CloseCommandRegion

        CommandBinding Closebinding = new CommandBinding(ApplicationCommands.Close, CommandCloseHandler);

        static void CommandCloseHandler(object target, ExecutedRoutedEventArgs e)
        {
            ((CategoryAddWindow)target).Close_Context();
        }

        #endregion

        void CategoryAddWindow_OnClosing(object sender, CancelEventArgs e)
        {
        }
    }
}
